package com.emapp.lccode.activity

import android.os.Bundle
import android.view.View
import com.emapp.lccode.R
import com.emapp.lccode.adapter.HomeTypeKTAdapter
import com.emapp.lccode.base.BaseActivity1
import com.emapp.lccode.base.EventBusConfig
import com.emapp.lccode.base.EventBusModel
import com.emapp.lccode.bean.HomeType
import com.emapp.lccode.databinding.ActivityHomeTypeBinding
import com.emapp.lccode.utils.grid
import com.emapp.lccode.utils.setOnclickNoRepeat
import com.emapp.lccode.utils.toStartActivity
import com.gyf.immersionbar.ktx.immersionBar
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 */
class HomeTypeKTActivity : BaseActivity1<BaseViewModel, ActivityHomeTypeBinding>() {
    var types1: ArrayList<HomeType> = arrayListOf()
    var types2: ArrayList<HomeType> = arrayListOf()
    var types3: ArrayList<HomeType> = arrayListOf()
    var types4: ArrayList<HomeType> = arrayListOf()
    private val homeTypeAdapter1: HomeTypeKTAdapter by lazy { HomeTypeKTAdapter() }
    private val homeTypeAdapter2: HomeTypeKTAdapter by lazy { HomeTypeKTAdapter() }
    private val homeTypeAdapter3: HomeTypeKTAdapter by lazy { HomeTypeKTAdapter() }
    private val homeTypeAdapter4: HomeTypeKTAdapter by lazy { HomeTypeKTAdapter() }
    override fun initView(savedInstanceState: Bundle?) {
        immersionBar {
            titleBar(mViewBind.lvTitle.ivBar)
            statusBarDarkFont(true)
            fullScreen(true)
            statusBarColor(R.color.transparent)
            navigationBarColor(R.color.white)
        }
        mViewBind.lvTitle.tvTitle.text="首页"
        mViewBind.lvTitle.tvRight.visibility = View.GONE
        EventBus.getDefault().register(this)
        types1.add(HomeType(R.drawable.home_shangbao, "工单管理"))
        types1.add(HomeType(R.drawable.home_lishixunjian, "问题上报"))
        types1.add(HomeType(R.drawable.home_check, "巡检日志"))
        homeTypeAdapter1.submitList(types1)
        types2.add(HomeType(R.drawable.home_xinzeng, "新增"))
        types2.add(HomeType(R.drawable.home_dikuai, "地块管理"))
        types2.add(HomeType(R.drawable.home_guanli, "设施设备管理"))
        homeTypeAdapter2.submitList(types2)
        types3.add(HomeType(R.drawable.home_yongche, "用车申请"))
        types3.add(HomeType(R.drawable.home_yongche2, "用车归还"))
        types3.add(HomeType(R.drawable.home_gongdan, "我的工单"))
        types3.add(HomeType(R.drawable.home_paidan, "派单管理"))
        types3.add(HomeType(R.drawable.home_budan, "补单"))
        homeTypeAdapter3.submitList(types3)
        types4.add(HomeType(R.drawable.home_dadian, "工程打点"))
        types4.add(HomeType(R.drawable.home_fankui, "意见反馈"))
        types4.add(HomeType(R.drawable.home_shenji, "工程审计"))
        homeTypeAdapter4.submitList(types4)
        mViewBind.rvList1.run {
            grid(4)
            adapter = homeTypeAdapter1
        }
        mViewBind.rvList2.run {
            grid(4)
            adapter = homeTypeAdapter2
        }
        mViewBind.rvList3.run {
            grid(4)
            adapter = homeTypeAdapter3
        }
        mViewBind.rvList4.run {
            grid(4)
            adapter = homeTypeAdapter4
        }
        homeTypeAdapter1.setOnItemClickListener { adapter, _, position ->
            val item = adapter.items[position]
            when (item.name) {
                "全部" -> {
                    toStartActivity(HomeTypeKTActivity::class.java)
                }

                "工单管理" -> {
                    toStartActivity(OrderManageKtActivity::class.java)
                }
            }
        }
        homeTypeAdapter2.setOnItemClickListener { adapter, _, position ->
            val item = adapter.items[position]
            when (item.name) {
                "全部" -> {
                    toStartActivity(HomeTypeKTActivity::class.java)
                }

                "工单管理" -> {
                    toStartActivity(OrderManageKtActivity::class.java)
                }
                "设施设备管理" -> {
                    toStartActivity(DeviceKtActivity::class.java)
                }
            }
        }
        homeTypeAdapter3.setOnItemClickListener { adapter, _, position ->
            val item = adapter.items[position]
            when (item.name) {
                "全部" -> {
                    toStartActivity(HomeTypeKTActivity::class.java)
                }

                "工单管理" -> {
                    toStartActivity(OrderManageKtActivity::class.java)
                }
            }
        }
        homeTypeAdapter4.setOnItemClickListener { adapter, _, position ->
            val item = adapter.items[position]
            when (item.name) {
                "全部" -> {
                    toStartActivity(HomeTypeKTActivity::class.java)
                }

                "工单管理" -> {
                    toStartActivity(OrderManageKtActivity::class.java)
                }
            }
        }
    }

    override fun createObserver() {
    }


    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }

    override fun onBindViewClick() {
        setOnclickNoRepeat(mViewBind.lvTitle.ivLeft, mViewBind.lvTitle.tvRight) {
            when (it.id) {
                R.id.iv_left -> {
                    finish()
                }
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onEventMainThread(event: EventBusModel) {
        when (event.type) {
            EventBusConfig.FINISH -> {
            }

            else -> {}
        }
    }

     fun onClick(view: View) {

    }
}
